package top.carrotguo.weibo.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;

public class ObservableScrollView extends NestedScrollView {

    private OnObservalbleScrollListener listener;

    public ObservableScrollView(@NonNull Context context) {
        super(context);
    }

    public ObservableScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ObservableScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (listener != null) {
            listener.onObservalbleScrollChanged(l,t,oldl,oldt);
        }
    }

    /**
     * 设置滑动监听
     * @param listener
     */
    public void setonObservalbleScrollListener(OnObservalbleScrollListener listener){
        this.listener = listener;
    }

    /**
     * 滑动监听
     */
    public interface OnObservalbleScrollListener {
        void onObservalbleScrollChanged(int l,int t, int oldl, int oldt);
    }

}
